package ualrcdg.shared.dto;

import ualrcdg.shared.exceptions.CDGTypeException;

/**
 * Simple implementation of the "fileMedia" object. See CDG XML Specifications: Game Descriptor Files.
 */
public class FileMedia extends Media
{
	/**
	 * Tag class for CDG fileMedia types.
	 */
	static enum FileType { audio, image, video };
	
	private final FileType type;
	private final String fileName;
	
	/**
	 * Primary constructor
	 *
	 * @param type the type of the FileMedia object to be created
	 * @param fileName the fileName of the FileMedia object to be created
	 * @throws CDGTypeException If the type specified is not valid.
	 */
	public FileMedia( String id, String name, String type, String fileName ) throws CDGTypeException
	{
		super( id, name );

		try
		{
			this.type = FileType.valueOf( type );
		}
		catch( IllegalArgumentException e )
		{
			throw new CDGTypeException( "The type: " + type + " is not a valid FileMedia type." );
		}
		
		this.fileName = fileName;
		
		System.out.println( "Parsed: " + this.toString( ) );
	}

	/*
	 * @see ualrcdg.shared.dto.Media#toString()
	 */
	@Override
	public String toString( )
	{
		return "FileMedia [<" + super.toString( ) + "> type=" + type + ", fileName=" + fileName + "]";
	}

	/**
	 * @return the type of this FileMedia instance
	 */
	public FileType getType( )
	{
		return type;
	}

	/**
	 * @return the fileName of this FileMedia instance
	 */
	public String getFileName( )
	{
		return fileName;
	}
}
